//
//  Synchronization+Calendars.m
//  exSync
//
//  Created by Alexander Chaika on 01.02.12.
//  Copyright 2012 by Alexander Chaika. All rights reserved.
//

#import "resource.h"

#import "Synchronization+Calendars.h"

@implementation Synchronization (Calendars)

- (void)updateCalendarsSyncScheduleWithInterval:(int)interval {
	self.calendarsNextSync = nil;
	if ([[NSUserDefaults standardUserDefaults] boolForKey:kSyncStarted] &&
		[[NSUserDefaults standardUserDefaults] boolForKey:kSyncCalendars] &&
		interval >= 0)
		self.calendarsNextSync = [NSDate dateWithTimeIntervalSinceNow:interval];
}

- (void)syncCalendars {
	if (!accessToken) // need access token to do sync
		return;
	
	if (calendarsState < 0) {
		// check sync contacts flag
		if (![[NSUserDefaults standardUserDefaults] boolForKey:kSyncCalendars])
			return;
		
		// check for sync time
		if (!calendarsNextSync || [calendarsNextSync timeIntervalSinceNow] > 0.)
			return;
		
		calendarsState = 0;
	}
}

@end
